#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;

const int N = 1e6;
int arr[N] = { 0 };
int a[N] = { 0 };

int main()
{
	int min = 0;
	int num = -1e6;
	int n = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= n; i++)
		arr[i] = arr[i - 1] + a[i];
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j < i; j++)
		{
			if (arr[j] < min)
			{
				min = arr[j];
			}
		}
		if (arr[i] - min > num)
		{
			num = arr[i] - min;
		}
	}
	cout << num << endl;
	return 0;
}